package com.focus.xyz.union.pages.frontend.forms;

import com.focus.xyz.core.common.keyword.Action;
import com.focus.xyz.core.pages.BaseForm;
import com.focus.xyz.core.utils.Constants;
import com.focus.xyz.union.data.WebSiteBean;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;

import java.util.List;

/**
 * Created by chenmeng on 2016/4/18.
 */
public class WebSiteForm extends BaseForm {
    @FindBy(id = "webSite")
    private WebElement form;

    @FindBy(id = "submit_btn")
    private WebElement nextBtn;

    public WebSiteForm(WebDriver driver,Action action){
        super(driver,action);
        PageFactory.initElements(driver,this);
    }
    public List<WebElement> getAllElements() throws Exception{
        List<WebElement> list = form.findElements(By.xpath("div/div/input|div/div/select|div/div/textarea"));
        /*for(WebElement e:list){
            System.out.println("private String " +e.getAttribute(Constants.ATTR_ID)+";");
        }*/
        return list;
    }

    //将网站数据对象绑定到表单并保存，适用于现在频道及修改频道时调用。
    public void saveSite(WebSiteBean bean) throws Exception{
        bind(bean);
        clickNextStepBtn();
    }
    public void clickNextStepBtn() throws Exception{
        action.click(this.nextBtn);
    }
}
